﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AlertSystem.PluggableModules;
using AlertSystem.Business;
using SKYPE4COMLib;

namespace AlertSystem.SendSkype
{
    public class SendAlert : WorkingBaseSendAlert
    {
        private SkypeClass skype = new SkypeClass();

        protected override void Send(Warning_Message msg, List<Warning_Account_Method> accountMethods)
        {
            try
            {
                if (!skype.Client.IsRunning)
                {
                    skype.Client.Start();
                    System.Threading.Thread.Sleep(1000);
                }
                var skype_users = accountMethods.Select(p => p.Account_Config);
                foreach (var user in skype_users)
                {
                    foreach (var item in user.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        try
                        {
                            skype.SendMessage(item, msg.Message);
                        }
                        catch (Exception ex)
                        {
                            Warning_Log.InsertLog(ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Warning_Log.InsertLog(ex);
            }
        }
    }
}
